// pages/shop/shop.js
var api = require('../../../app/app.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nothing: 'https://www.sdhjfu.com/smallhouse/public/house/images/no.jpg',
    showPage: true,
    IMG_URL: 'https://www.sdhjfu.com/tooltwo/public/admin/',
    integralNum: 0,
    icon1: 'https://www.sdhjfu.com/smallhouse/public/tianxing/images/shop_icon1.jpg',
    icon2: 'https://www.sdhjfu.com/smallhouse/public/tianxing/images/shop_icon2.jpg',
    items: [],
    goodsId: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '商城'
    })
  },
  goodClick: function (e) {
    var ind = e.currentTarget.id
    var items = e.currentTarget.dataset.info;
    var goodsId = items.goods_id
    var goodsNam = JSON.stringify(items.goods_name)
    wx.navigateTo({
      url: '../components/shopDetails/shopDetails?goodsId=' + goodsId + '&goodsNam=' + goodsNam,
    })
  },
  exchangeClick: function() { // 跳转到兑换记录
    wx.navigateTo({
      url: '../components/exchange/exchange'
    })
  },
  introClick: function () { // 跳转到积分攻略
    wx.navigateTo({
      url: '../components/introduction/introduction'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    wx.getStorage({ // 获取本地缓存
      key: 'userReInfo',
      success(res) {
        // console.log(res.data)
        var phone = res.data.phone
        var userId = res.data.userId
        if (!phone) {
          that.setData({
            showPage: true
          })
        } else {
          that.setData({
            showPage: false
          })
        }
        // 获取商品的信息
        wx.request({
          url: api.ShopGoods,
          method: 'POST',
          data: {
            userId: userId
          },
          header: {
            'content-Type': 'application/x-www-form-urlencoded' // post请求头
          },
          success: function (res) {
           // console.log(res.data)
            that.setData({
              items: res.data.goodsre,
              integralNum: res.data.intercount
            })
          }
        })
      }
    })
  },
  butLogin: function () {
    wx.showModal({
      title: '您还未登陆',
      content: '请先登录再进行操作',
      success(res) {
        if (res.confirm) {
          //console.log('用户点击确定')
          wx.redirectTo({
            url: '/pages/authorization/authorization'
          })
        } else if (res.cancel) {
          //console.log('用户点击取消')
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})